<?php

namespace App\Http\Requests\Admin\V1;

use Illuminate\Validation\Rule;

class RoleUpdateRequest extends FormRequest
{
    /**
     * @expalin 验证规则
     * @return array
     * @method
     * @author 陈文小超
     * @maxim from专注to执行
     * @time 2021/3/31/15:06
     */
    public function rules()
    {
        return [
            'id'          => ['bail', 'required', 'integer', 'min:1'],
            'name'        => ['bail', 'required', 'max:20', Rule::unique('roles', 'name')->ignore(self::input('id'))],
            'menus'       => ['bail', 'present', 'array'],
            'permissions' => ['bail', 'present', 'array'],
            'is_enable'   => ['bail', 'required', 'boolean'],
        ];
    }

    /**
     * @expalin 自定义错误抛出
     * @return array
     * @method
     * @author 陈文小超
     * @maxim from专注to执行
     * @time 2021/3/31/15:07
     */
    public function messages()
    {
        return [
            'id.required'        => trans('admin/v1/request.role.id-required'),
            'id.integer'         => trans('admin/v1/request.role.id-integer'),
            'id.min'             => trans('admin/v1/request.role.id-min'),
            'name.required'      => trans('admin/v1/request.role.name-required'),
            'name.max'           => trans('admin/v1/request.role.name-max'),
            'name.unique'        => trans('admin/v1/request.role.name-unique'),
            'menus.array'        => trans('admin/v1/request.role.menus-array'),
            'permissions.array'  => trans('admin/v1/request.role.permissions-array'),
            'is_enable.required' => trans('admin/v1/request.role.is_enable-required'),
            'is_enable.boolean'  => trans('admin/v1/request.role.is_enable-boolean'),
        ];
    }
}
